<template>
  <div :style="'width:' + width">
    <el-form :label-width="labelWidth" label-position="left" :disabled="disabled">
      <el-form-item :label="name" :required="required">
        <el-input style="flex: 1" v-model="data.text" :type="type" @input="input" :maxlength="maxlength"
          :placeholder="placeholder" :rows="rows" :disabled="disabled"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: ['value', 'disabled', 'props', 'required', 'isBusiness'],
  data: function () {
    return {
      data: {
        text: null,
        displayName: '',
      },
    }
  },
  computed: {
    myprops() {
      return this.props ? this.props : []
    },
    labelWidth() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'labelWidth')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '140px'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '140px'
        }
      }
      return '140px'
    },
    width() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'width')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '100%'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '100%'
        }
      }
      return '100%'
    },
    maxlength() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'maxlength')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : null
        } else {
          return val.FFLP_Value ? val.FFLP_Value : null
        }
      }
      return null
    },
    name() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'name')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '文本框'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '文本框'
        }
      }
      return '文本框'
    },
    placeholder() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'placeholder')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '请输入' + this.name
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '请输入' + this.name
        }
      }
      return '请输入' + this.name
    },
    type() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'type')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : 'text'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : 'text'
        }
      }
      return 'text'
    },
    rows() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'rows')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? Number(val.BFFP_Value) : 1
        } else {
          return val.FFLP_Value ? Number(val.FFLP_Value) : 1
        }
      }
      return 1
    },
  },
  methods: {
    input() {
      this.data.displayName = this.data.text
      this.$emit('input', JSON.stringify(this.data))
      this.$emit('display', this.data.displayName)
    },
  },
  mounted: function () {
    if (this.value) {
      this.data = JSON.parse(this.value)
    }
  },
}
</script>
<style scoped>
.el-form-item {
  margin: 10px !important;
}
</style>